package com.cxf.cxfdaybat.job.processor;

import com.cxf.cxfdaybat.entity.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.validator.ValidatingItemProcessor;
import org.springframework.batch.item.validator.ValidationException;
import org.springframework.stereotype.Component;

/**
 * description: CvsItemProcessor <br>
 * date: 2021/11/11 23:29 <br>
 * author: cxf <br>
 * version: 1.0 <br>
 *  ValidatingItemProcessor<Person>
 */

public class CvsItemProcessor implements ItemProcessor<Person,Person> {
    private Logger logger = LoggerFactory.getLogger(CvsItemProcessor.class);

    @Override
    public Person process(Person item) throws ValidationException {
        // 执行super.process()才能调用自定义的校验器
        logger.info("processor start validating...");
       // super.process(item);

        // 数据处理，比如将中文性别设置为M/F
        if ("男".equals(item.getGender())) {
            item.setGender("M");
        } else {
            item.setGender("F");
        }
        logger.info("processor end validating...");
        return item;
    }
}